<template>
<div>
  <div>
  <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
    <el-breadcrumb-item :to="{ path: '/admin/index' }">
      <i class="el-icon-s-promotion"></i>
      管理后台首页
    </el-breadcrumb-item>
    <el-breadcrumb-item :to="{path: '/admin/older/list'}">老人健康信息</el-breadcrumb-item>
    <el-breadcrumb-item>老人健康信息修改</el-breadcrumb-item>
  </el-breadcrumb>
  <el-divider></el-divider>

    <el-card class="box-card">
      <h1 style="font-size: 25px;margin-bottom: 25px;text-align: center">老人健康信息修改</h1>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="老人姓名:" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="联系方式:" prop="phoneNumber">
          <el-input v-model="ruleForm.phoneNumber"></el-input>
        </el-form-item>
        <el-form-item label="性别:" prop="gender">
          <el-input v-model="ruleForm.gender"></el-input>
        </el-form-item>
        <el-form-item label="年龄:" prop="age">
          <el-input v-model="ruleForm.age"></el-input>
        </el-form-item>

        <el-form-item label="老人生日:" prop="birth">
          <el-date-picker
              v-model="ruleForm.birth"
              type="datetime"
              placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身高:" prop="height">
          <el-input v-model="ruleForm.height"></el-input>
        </el-form-item>
        <el-form-item label="体重:" prop="weight">
          <el-input v-model="ruleForm.weight"></el-input>
        </el-form-item>
        <el-form-item label="血压:" prop="bp">
          <el-input v-model="ruleForm.bp"></el-input>
        </el-form-item>
        <el-form-item label="血糖:" prop="bg">
          <el-input v-model="ruleForm.bg"></el-input>
        </el-form-item>
        <el-form-item label="血脂:" prop="bl">
          <el-input v-model="ruleForm.bl"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      ruleForm: {
        id:"",
        name: '',
        gender:'',
        age:'',
        phoneNumber:'',
        birth: '',
        height: '',
        weight: '',
        bp: '',
        bg: '',
        bl: ''
      },
      rules: {
        name: [
          { required: true, message: '请选择老人信息', trigger: 'blur' }
        ],
        date:[
          { required: true, message: '请选择入住时间', trigger: 'blur' }
        ]
      },
       tableShow:false,
      Content: "",
      tableData: [],
      currentRow: null
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = 'http://localhost:8080/olders/'+location.search.split("=")[1]+'/update';
          console.log('url = ' + url);

          this.axios
              .create({'headers': {'Authorization': localStorage.getItem('jwt') }})
              .post(url, this.ruleForm).then((response)=>{
            if(response.data.state==20000)
            {
              this.$message.success("修改成功！");
            location.href= "/admin/older/list";
            }
            else {
              this.$message.error(response.data.message);
            }
          })

        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  created:function ()
  {
    this.axios
        .create({'headers': {'Authorization': localStorage.getItem('jwt') }})
        .get("http://localhost:8080/olders/"+location.search.split("=")[1])
    .then((response)=>
    {
      let responseBody = response.data;
      if (responseBody.state == 20000) {
        this.ruleForm = responseBody.data;
      }
    })
  }
}
</script>

<style>
.box-card{
  width: 80%;
  height: 800px;
  margin: 0 auto;
}
.demo-ruleForm{
  width: 50%;
  margin: 0 auto;
}

.el-input {
  width: 500px;
}
</style>